package com.example.demo.servlet;

import com.example.demo.dao.CartDao;
import com.example.demo.dao.UserDao;
import com.example.demo.entity.CartVo;
import com.example.demo.entity.UserCartVo;
import com.example.demo.entity.UserVo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/findcart")
public class FindCartServlet extends HttpServlet {

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        UserVo user = (UserVo) req.getSession().getAttribute("user");
        try {
            List<UserCartVo> cartByUserid = new CartDao().getCartByUserid(user.getUserID());
            req.setAttribute("cart",cartByUserid);
            req.getRequestDispatcher("/shop.jsp").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }

    }
}
